#include "myd3dutil.h"

namespace lwd3dutil{
	int d3dDrawText(IDirect3DDevice9* Device, std::string str, float x, float y, float z)
	{
		D3DXMATRIX p(1,0,0,0,
			0,1,0,0,
			0,0,1,0,
			x,y,z,1);
		Device->SetTransform(D3DTS_WORLD,&p);
		HDC hdc = ::CreateCompatibleDC(0);
		HFONT hFont;
		HFONT hFontOld;

		LOGFONTA lf;
		ZeroMemory(&lf, sizeof(LOGFONTA));

		lf.lfHeight = 1;
		lf.lfWidth = 1;
		lf.lfEscapement = 0;
		lf.lfOrientation = 0;
		lf.lfWeight = 10;
		lf.lfItalic = false;
		lf.lfUnderline = false;
		lf.lfStrikeOut = false;
		lf.lfCharSet = DEFAULT_CHARSET;
		lf.lfOutPrecision = 0;
		lf.lfClipPrecision = 0;
		lf.lfQuality = 0;
		lf.lfPitchAndFamily = 0;
		strcpy(lf.lfFaceName, "Times New Roman");

		hFont = ::CreateFontIndirectA(&lf);
		hFontOld = (HFONT)SelectObject(hdc, hFont);
		SelectObject(hdc, (HPEN)GetStockObject(BLACK_PEN));
		
		LPD3DXMESH Text = NULL;
		::D3DXCreateTextA(Device, hdc, str.c_str(), 0.000f, 0.0000001, &Text, 0, 0);

		SelectObject(hdc, hFontOld);
		DeleteObject(hFont);
		DeleteDC(hdc);

		Text->DrawSubset(0);
		
		return 0;
	}
}